package config

import "gitee.com/dreamwood/ez"

type ServiceConfig struct {
	App struct {
		Id   string `yaml:"id"`
		Name string `yaml:"name"`
	} `yaml:"app"`
	Dependence  map[string]string `yaml:"dependence"`
	LoadBalance struct {
		Name   string `yaml:"name"`
		Weight int    `yaml:"weight"`
	} `yaml:"load-balance"`
	Register struct {
		Host             string `yaml:"host"`
		Auth             string `yaml:"auth"`
		HearBeatInterval int    `yaml:"hear-beat-interval"`
	} `yaml:"register"`
	Routes []struct {
		From string `yaml:"from"`
		To   string `yaml:"to"`
		Sort int    `yaml:"sort"`
		Port string `yaml:"port"`
	} `yaml:"routes"`
	//以下非配置項
	RunPath string
	Host    string
	Port    string
	Pid     int
}

var serviceConfig *ServiceConfig

func init() {
	CreateServiceConfig()
}

func CreateServiceConfig() {
	ez.CreateConfigFromYml("./app.yaml", "service", &serviceConfig)
}

func GetService() *ServiceConfig {
	if serviceConfig == nil {
		CreateServiceConfig()
	}
	return serviceConfig
}
